home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / graphics.17 / graphics / graphics-0.17 / plot2tek / alabel.c next >
Encoding:
C/C++ Source or Header  |  1991-03-12  |  3.8 KB  |  136 lines

  1. #include "sys-defines.h"
  2. #include "libplot.h"
  3.  
  4. /* TEXT_ROTATION is the angle in degress counterclockwise from the
  5.    horizontal for rotation of labels. */
  6.  
  7. int text_rotation=0;
  8.  
  9. /* FONT_SIZE is the font size in printer's points (-f option). */
  10.  
  11. double font_size = 14.;
  12.  
  13. /* ALABEL takes three arguments X_JUSTIFY, Y_JUSTIFY, and S and places
  14.    the label S according to the x and y axis adjustments specified in
  15.    X_JUSTIFY and Y_JUSTIFY respectively.  X_JUSTIFY is a character
  16.    containing either l, c, or r for left, center or right justified with
  17.    respect to the current x coordinate.  Y_JUSTIFY is a character
  18.    containing either b, c, or t for placing the bottom center or top of
  19.    the label even with the current y coordinate. S is a string containing
  20.    the label. The current point is moved to follow the end of the text. */
  21.  
  22. int
  23. alabel (x_justify, y_justify, s)
  24.      int x_justify, y_justify;
  25.      char *s;
  26. {
  27.   int xposn, yposn;
  28.   double width, theta;
  29.   double x_char_offset = 0., x_extra = 0., y_char_offset = 0.;
  30.  
  31.   width = strlen (s);
  32.   switch (x_justify)
  33.     {
  34.     case 'l': /* left justified */
  35.       x_char_offset = 0.0;
  36.       break;
  37.  
  38.     case 'c': /* centered */
  39.       x_char_offset = 0.5;
  40.       break;
  41.  
  42.     case 'r': /* right justified */
  43.       x_char_offset = 1.;
  44.       x_extra = .4;
  45.       break;
  46.     }
  47.  
  48.   switch (y_justify)
  49.     {
  50.     case 'b': /* bottom */
  51.       y_char_offset = 0.;
  52.       break;
  53.  
  54.     case 'c': /* centered */
  55.       y_char_offset = .6;
  56.       break;
  57.  
  58.     case 't': /* top */
  59.       y_char_offset = 1.5;
  60.       break;
  61.     }
  62.  
  63.   /* Position the text according to the justification and text
  64.      rotation.  If necessary, the cursor is moved to a new
  65.      location where the string would begin. */
  66.   
  67.   theta = text_rotation * M_PI / 180;
  68.   
  69.   xposn = last_x;
  70.   yposn = last_y;
  71.   if ( (x_char_offset != 0.)
  72.     || (y_char_offset != 0.))
  73.     {
  74.       xposn = last_x - (int) (font_size * x_char_offset
  75.                 * (width + x_extra) * scaleup * cos(theta));
  76.       yposn = last_y - (int) (font_size * y_char_offset * scaleup * cos(theta));
  77.       move (xposn, yposn);
  78.     }
  79.  
  80.  
  81.   if (text_rotation == 0) {
  82.       /* No rotation, so do it the easy way */
  83.       putc ('\037', stdout);
  84.       fputs (s, stdout);
  85.   } else if (text_rotation == 90) {
  86.       /* This is a special case.  If text rotation is 90 (for
  87.      labels on the y-axis), plot the label down, instead
  88.      of up as would normally be done. */
  89.       char *ptr;
  90.       int cnt;
  91.  
  92.       cnt = strlen(s);
  93.       ptr = s + cnt;
  94.       while (cnt-- > 0) {
  95.       putchar ('\037');
  96.       putchar (*--ptr);
  97.       yposn += 1.3 * font_size * scaleup;
  98.       move (xposn, yposn);
  99.       }
  100.   } else {
  101.       /* General case:  move the cursor and plot each
  102.      character individually */
  103.       
  104.       int dx, dy;
  105.  
  106.       dx = 0.5 + font_size * scaleup * cos(theta);
  107.       dy = 0.5 + font_size * scaleup * sin(theta);
  108.  
  109.       while (*s) {
  110.       putchar ('\037');
  111.       putchar (*s);
  112.       xposn += dx;
  113.       yposn += dy;
  114.       move (xposn, yposn);
  115.       s++;
  116.       }
  117.   }
  118.  
  119.   return 0;
  120. }
  121. /* libtek, a library of functions for tektronics 4010 compatible devices.
  122.    Copyright (C) 1989 Free Software Foundation, Inc.
  123.  
  124. libtek is distributed in the hope that it will be useful, but WITHOUT ANY
  125. WARRANTY.  No author or distributor accepts responsibility to anyone for the
  126. consequences of using it or for whether it serves any particular purpose or
  127. works at all, unless he says so in writing.  Refer to the GNU General Public
  128. License for full details.
  129.  
  130. Everyone is granted permission to copy, modify and redistribute libtek, but
  131. only under the conditions described in the GNU General Public License.  A copy
  132. of this license is supposed to have been given to you along with libtek so
  133. you can know your rights and responsibilities.  It should be in a file named
  134. COPYING.  Among other things, the copyright notice and this notice must be
  135. preserved on all copies.  */
  136.